<?php htmlTemplate('index/header.php')?>
<script>
(function($){
    bnums=0;
	$.fn.insertRoundCaret = function (tagName) {
		
        if(bnums==6){
            alert('at most fill '+bnums+' blanks');
            return false;
        }
        bnums++;
		return this.each(function(){
			strStart = '['+tagName+']';
			strEnd = '[/'+tagName+']';
			if (document.selection) {
				//IE support
				stringBefore = this.value;
				this.focus();
				sel = document.selection.createRange();
				insertstring = sel.text;
				fullinsertstring = strStart + sel.text + strEnd;
				sel.text = fullinsertstring;
				document.selection.empty();
				this.focus();
				stringAfter = this.value;
				i = stringAfter.lastIndexOf(fullinsertstring);
				range = this.createTextRange();
				numlines = stringBefore.substring(0,i).split("\n").length;
				i = i+3-numlines+tagName.length;
				j = insertstring.length;
				range.move("character",i);
				range.moveEnd("character",j);
				range.select();
			}else if (this.selectionStart || this.selectionStart == '0') {
				//MOZILLA/NETSCAPE support
				startPos = this.selectionStart;
				endPos = this.selectionEnd;
				scrollTop = this.scrollTop;
				this.value = this.value.substring(0, startPos) + strStart + this.value.substring(startPos,endPos) + strEnd + this.value.substring(endPos,this.value.length);
				this.focus();
				this.selectionStart = startPos + strStart.length ;
				this.selectionEnd = endPos + strStart.length;
				this.scrollTop = scrollTop;
			} else {
				this.value += strStart + strEnd;
				this.focus();
			}
		});
	};
	})(jQuery)
</script>
		<div class="nav">			
			<span class="nav_span">
			<a class="nav_home" href="<?php echo MVC_WWW_HOST;?>">&nbsp;</a>
			<a href="<?php echo MVC_WWW_HOST?>library/index">Library</a> :: 
			Add Questions
			</span>
		</div>
		<div class="common_search_wrap" style="text-align:left">
        Quiz title <input type="text" class="input1" id="title">
		Quiz to cate:
            <select name="cate" id="cate" >            	
            	<?php
            	if ($cates){
            		foreach ($cates as $k=>$v): 
            		?>
            		<option value="<?php echo $v['id']?>"><?php echo $v['name']?></option>
            		<?php 
            		endforeach;
            		echo '<option value="0">默认分类</option>';
            	}else {
            		echo '<option value="0">默认分类</option>';
            	}?>
            </select>
            <input type="button" class="add_btn" onclick="addCate('addcate')" />
            <span id="addcate" style="display:none;">
            <input type="text" class="input3" id="savecate"> <input type="button" class="search_submit2" onclick="saveCate()" value="Save">
            </span>
		</div>
		<div class="lib_add_wrap">
			
			
			<table class="com_table" cellspacing="1" cellpadding="3" >			  
			  		  
			 
			  <tr>
			    <td colspan="2">&nbsp;Set Answer:</td>
			   	    
			  </tr>
			 
			  <tr>
			    <td colspan="2"  class="com_tbd" id="questions">
                  
                </td>
			        
			  </tr>
				  
			
			  <tr class="com_table_tr2">
			  	<td>&nbsp;</td>
			  	<td><input type="button" value="Save" class="search_submit" onclick="saveAnswer()"></td>
			  </tr>
			</table>
			
		</div>

<script type="text/javascript">

function addCate(id){
	$("#"+id).fadeIn();
}
function saveCate(){
	var savecate = $.trim($("#savecate").val());
	url = '<?php echo MVC_WWW_HOST;?>quiz/addcate.html';
	$.getJSON(url,{'savecate':savecate},function(data){
		alert(data.html);
		if(data.rs==1){
			var row = '<option value="'+ data.id +'">' +savecate+ '</option>';
			var tmpHtml = $("#cate").html();
			$("#cate").html(row+tmpHtml);
		}
		
	})
}
$(document).ready(function(){
	var sh=screen.height;	
	getHtml('<?php echo MVC_WWW_HOST;?>library/questions/height/'+sh+'.html','questions');
	
})
</script>		
<?php htmlTemplate('index/footer.php')?>
